import api from '../httpRequest.js'

// 登录
function accountLogin(data) {
    return api.post({
        url: window.iotWebConfig?.iotUrl + '/api/v1/account/login2',
        data
    })
}
// 老版本登录
function accountLoginOld(data) {
    return api.post({
        url: window.iotWebConfig?.iotUrl + '/api/v1/account/login',
        data
    })
}

// 获取用户信息
function accountInfo() {
    return api.get({
        url: window.iotWebConfig?.iotUrl + '/api/v1/account'
    })
}

// 获取系统配置信息
function getWebConfig(params) {
    return api.get({
        url: '/getconfig/webconfig',
        params
    })
}

// 退出登录
function accountLogOut(data) {
    return api.post({
        url: '/account/logOut',
        data
    })
}

// 通过用户查询关联组织
function getOrgByUser(userId, params) {
    return api.get({
        url: window.iotWebConfig?.iotUrl + '/api/v2/organization/user/' + userId,
        params
    })
}

// 获取单个设备详情
function getDevice(deviceName, params) {
    return api.get({
        url: window.iotWebConfig?.iotUrl + '/api/v2/devices/'+deviceName,
        params
    })
}

// 获取设备列表
function getDeviceAllPost(data) {
    return api.post({
        url: window.iotWebConfig?.iotUrl + '/api/v2/devices/post',
        data
    })
}

// V2执行动作
function executeActionByIdentifier(data) {
    return api.post({
        url: window.iotWebConfig?.iotUrl + '/api/v2/devices/commands/input',
        data
    })
}

// 获取实时事件
function getRealTimeMessages(params) {
    return api.get({
        url: window.iotWebConfig?.iotUrl + '/api/v1/message/realTime',
        params
    })
}

// 获取设备事件V1
function getDeviceMessages2(data) {
    return api.post({
        url: window.iotWebConfig?.iotUrl + '/api/v1/message/device2',
        data
    })
    // api/v2/message?begintime=xxx&endtime=xxx&deviceTypes=xxx
}

// 获取设备事件
function getDeviceMessages(params) {
    return api.get({
        url: window.iotWebConfig?.iotUrl + '/api/v2/message',
        params
    })
    // api/v2/message?begintime=xxx&endtime=xxx&deviceTypes=xxx
}

// 获取人员轨迹列表
function getPersonnelTrajectory(params) {
    return api.post({
        url: window.iotWebConfig?.iotUrl + '/api/v1/people/track',
        params
    })
}
const webApi = {
    accountLogin,
    accountLoginOld,
    accountInfo,
    getWebConfig,
    accountLogOut,
    getOrgByUser,
    getDevice,
    executeActionByIdentifier,
    getDeviceAllPost,
    getRealTimeMessages,
    getPersonnelTrajectory,
    getDeviceMessages2,
    getDeviceMessages
}
window.webApi = webApi
export default webApi
